Install PHP 5.6
2016/07/05 |
The version of PHP in CentOS 7 repository is 5.4 but Install 5.6 with RPM package if you need.
|
|
[1] | It's possible to install from CentOS SCLo Software Collections. It's OK to install it even if 5.4 is already installed because 5.6 is located on another PATH. |
# install from SCLo [root@dlp ~]# yum --enablerepo=centos-sclo-rh -y install rh-php56
|
[2] | Packages from Software Collections are installed uder the /opt directory. To use it, Load environment variables like follows. |
# load environment variables [root@dlp ~]# scl enable rh-php56 bash
[root@dlp ~]#
[root@dlp ~]# php -v PHP 5.6.5 (cli) (built: Mar 23 2016 19:17:38) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies which php /opt/rh/rh-php56/root/usr/bin/php |
[3] | If you'd like to enable PHP 5.6 automatically at login time, configure like follows. |
[root@dlp ~]#
vi /etc/profile.d/rh-php56.sh # create new #!/bin/bash source /opt/rh/rh-php56/enable export X_SCLS="`scl enable rh-php56 'echo $X_SCLS'`" |
[4] | To use 5.6 on Apache httpd, Configure PHP-FPM like follows. |
# install from SCLo
[root@dlp ~]#
yum --enablerepo=centos-sclo-rh -y install rh-php56-php-fpm
[root@dlp ~]#
vi /etc/httpd/conf.d/php.conf # line 5: change like follows <FilesMatch \.php$> # SetHandler application/x-httpd-php
SetHandler "proxy:fcgi://127.0.0.1:9000" </FilesMatch> systemctl start rh-php56-php-fpm [root@dlp ~]# systemctl enable rh-php56-php-fpm [root@dlp ~]# systemctl restart httpd |
[5] | If you'd like to use 5.6 as embedded on Apache httpd, Configure like follows. |
# install from SCLo
[root@dlp ~]#
yum --enablerepo=centos-sclo-rh -y install rh-php56-php
[root@dlp ~]#
vi /etc/httpd/conf.modules.d/10-php.conf # change like follows
<IfModule prefork.c>
LoadModule php5_module /opt/rh/httpd24/root/usr/lib64/httpd/modules/librh-php56-php5.so
</IfModule>
[root@dlp ~]#
systemctl restart httpd # create phpinfo to verify working [root@dlp ~]# echo '<?php phpinfo(); ?>' > /opt/rh/httpd24/root/var/www/html/info.php [root@dlp ~]# curl http://localhost/info.php | grep 'PHP Version' | tail -1 | sed -e 's/<[^>]*>//g' % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 68819 0 68819 0 0 5529k 0 --:--:-- --:--:-- --:--:-- 6109kPHP Version 5.6.5 |